

UIDCHK:=$(shell id -u)
ifeq ($(UIDCHK),0)
$(error UID=0,run in root,exit.)
endif
#specify cross compile prefix
CROSS_COMPLIE=

AS   = $(CROSS_COMPLIE)as
LD   = $(CROSS_COMPLIE)ld
CC   = $(CROSS_COMPLIE)gcc
CPP  = $(CROSS_COMPLIE)g++
AR   = $(CROSS_COMPLIE)ar
NM   = $(CROSS_COMPLIE)nm

STRIP    = $(CROSS_COMPLIE)strip
OBJDUMP  = $(CROSS_COMPLIE)objdump
OBJCOPY  = $(CROSS_COMPLIE)objcopy

#export these for sub make
export AS LD CC CPP AR NM
export STRIP OBJDUMP OBJCOPY

TOPDIR := $(shell pwd)
__BUILDDIR=build
BUILDDIR = $(TOPDIR)/$(__BUILDDIR)
#complier paramaters
CFLAGS     := -Wall -O2 -g -std=c99  -D_GNU_SOURCE
CFLAGS     += -I$(TOPDIR)/cjson -I$(TOPDIR)/sdk -I$(TOPDIR)/src  -I$(TOPDIR)
LDFLAGS    := -lm -lpthread

#export for sub make
export CFLAGS LDFLAGS

export TOPDIR BUILDDIR
 
STAMP=$(shell date +%Y%m%d%H%M)

TARGET := smartgw3rdsdk
export TARGET
obj-y  +=src/ 
obj-y  +=cjson/
obj-a  +=sdk/


all:
	make -C ./ -f ${TOPDIR}/script/Makefile.build
	make -C $(obj-a) -f ${TOPDIR}/script/MakefileAR.build
	cp $(BUILDDIR)/$(obj-a)built-in.a $(BUILDDIR)/$(TARGET).a 
	$(CC)  -o $(BUILDDIR)/$(TARGET) $(BUILDDIR)/built-in.o  $(BUILDDIR)/$(TARGET).a $(LDFLAGS) 


clean:
	rm -f $(shell find -name "*.o")
	rm -f $(TARGET)

distclean:
	-rm ./$(__BUILDDIR) -rf
	-rm ./$(TARGET)-*.tar.gz -f

dist:
	rm ~/.$(STAMP) -rf
	mkdir ~/.$(STAMP) -p
	cp ./* ~/.$(STAMP) -r -p
	rm ~/.$(STAMP)/$(__BUILDDIR) -rf
	tar zcPf $(TARGET)-$(STAMP).tar.gz  ~/.$(STAMP)/*
	rm ~/.$(STAMP)/ -rf

distcheck:
	echo "distcheck do nothing..."

install:
	echo "install do nothing..."

uninstall:
	echo "uninstall do nothing..."


